﻿<%@ WebHandler Language="C#" Class="EvaluateHandlerService" %>

using System;
using System.Web;



using System.Collections;
using System.Collections.Generic;
using System.Reflection;

using XJX.BusinessLayer;

using XJX.Page;

public class EvaluateHandlerService : IHttpHandler, System.Web.SessionState.IRequiresSessionState
{

    public void ProcessRequest(HttpContext context)
    {
        context.Response.ContentType = "application/json";

        string response = "";

        String methodName = context.Request["method"];
        Type type = this.GetType();
        MethodInfo method = type.GetMethod(methodName);


        if (method == null)
        {
            response = new XJX.Page.JsonResult(XJX.Page.StatusMessageType.Hint, "调用的方法不存在！").ToJson(); return;
        }

        try
        {
            BeforeInvoke(methodName);
            response = method.Invoke(this, null).ToString();
        }
        catch (Exception ex)
        {
            Hashtable result = new Hashtable();
            result["error"] = -1;
            result["message"] = ex.Message;
            result["stackTrace"] = ex.StackTrace;
            String json = XJX.BusinessLayer.JSON.Encode(result);
            context.Response.Clear();
            context.Response.Write(json);
        }
        finally
        {
            AfterInvoke(methodName);
            HttpContext.Current.Response.Write(response);
        }
    }

    public bool IsReusable
    {
        get
        {
            return false;
        }
    }

    //权限管理
    protected void BeforeInvoke(String methodName)
    {
        //Hashtable user = GetUser();
        //if (user.role == "admin" && methodName == "remove") throw .      
    }
    //日志管理
    protected void AfterInvoke(String methodName)
    {

    }


    //===============================================================================================================================================
    //===============================================================================================================================================
    //===============================================================================================================================================
    //===============================================================================================================================================
    //===============================================================================================================================================


    public string Add_New_Evaluate()
    {
        FamilyInfo fi = (FamilyInfo)HttpContext.Current.Session["FamilyInfo"];
        string UID = fi.UID;

        string BID = HttpContext.Current.Request["BID"];
        string Econtent = HttpContext.Current.Request["EvalContent"];
        
        if (!Helper.VerificationStr(Econtent))
        {
            return new XJX.Page.JsonResult(XJX.Page.StatusMessageType.Error, "书评中不能包含一些特殊字符，请检查!").ToJson();
        }
        
        int Egrade = int.Parse(HttpContext.Current.Request["EvalGrade"].ToString());

        int ReturnValue = 0;
        string ReturnFieldValue = "";
        
        
        
        //下面开始调用信息保存
        bool b = XJX.Page.Evaluate.Add_New_Evaluate(BID, UID,Econtent,Egrade, out ReturnValue, out ReturnFieldValue);

        string result = "";
        switch (ReturnValue)
        {
            case 1:
                result = new XJX.Page.JsonResult(XJX.Page.StatusMessageType.Success, "书评添加成功，它的编号是：" + ReturnFieldValue).ToJson();
                break;
            case 99:
                result = new XJX.Page.JsonResult(XJX.Page.StatusMessageType.Error, "添加书评失败，请检查数据!").ToJson();
                break;
        }
        return result;
    }

    public string Get_One_Book_Evaluate_From_BID()
    {
        string BID = HttpContext.Current.Request["BID"];
        int PageIndex = Convert.ToInt32(HttpContext.Current.Request["PageIndex"]);
        int PageSize = Convert.ToInt32(HttpContext.Current.Request["PageSize"]);

        return XJX.Page.Evaluate.Get_One_Book_Evaluate_From_BID(BID,PageIndex, PageSize);
    }
    
   public string  Shielding_One_Evaluate_From_EID()
   {
       string result = "";

       string EID = HttpContext.Current.Request.Form["EvaluateID"];

       bool b = XJX.Page.Evaluate.Shielding_One_Evaluate_From_EID(EID);

       if (b)
       {
           result = new XJX.Page.JsonResult(XJX.Page.StatusMessageType.Success, "屏敝成功!").ToJson();
       }
       else
       {
           result = new XJX.Page.JsonResult(XJX.Page.StatusMessageType.Error, "屏敝失败!").ToJson();
       }
       return result;
   }
    
    
    

}